<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      .father {
        width: 200px;
        height: 200px;
        background-color: pink;
        margin-top: 20px;
      }
      .son {
        width: 100px;
        height: 100px;
        background-color: skyblue;
      }
    </style>
  </head>
  <body>
    <div id="app">
      <h3>v-model修饰符 .trim .number</h3>
      <!-- v-model.trim 去除首尾空格 -->
      姓名：<input v-model.trim="username" type="text" /><br />
      <!-- v-model.number 转数字(非强制转换) 你输入的得是合法的数字, 如果不合法则原样返回 -->
      年纪：<input v-model.number="age" type="text" /><br />

      <h3>@事件名.stop → 阻止冒泡</h3>
      <div @click="fatherFn" class="father">
        <!-- 阻止冒泡 -->
        <div @click.stop="sonFn" class="son">儿子</div>
      </div>

      <h3>@事件名.prevent → 阻止默认行为</h3>
      <!-- 点击时会默认跳转到href后面的地址对应的页面中去 -->
      <!-- @事件名.prevent 阻止默认行为 -->
      <a @click.prevent="aFn" href="http://www.baidu.com">阻止默认行为</a>
    </div>
    <script src="https://cdn.jsdelivr.net/npm/vue@2/dist/vue.js"></script>
    <script>
      const app = new Vue({
        el: "#app",
        data: {
          username: "",
          age: "",
        },
        methods: {
          fatherFn() {
            alert("老父亲被点击了");
          },
          sonFn(e) {
            // e.stopPropagation()
            alert("儿子被点击了");
          },
          aFn() {
            console.log("a标签被点击了");
            setTimeout(() => {
              window.location.href = "http://www.baidu.com";
            }, 3000);
          },
        },
      });
    </script>
  </body>
</html>
